package chou;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;

public class MyThread extends Thread {
    ArrayList<Integer> list;
    HashMap<String,ArrayList<Integer>> recordMap;
    public MyThread( ArrayList<Integer> list, HashMap<String,ArrayList<Integer>> recordMap) {
        this.recordMap = recordMap;
        this.list = list;
    }
    @Override
    public void run() {
        while(true){

            synchronized (MyThread.class){

                if(list.isEmpty()){
                    break;
                }else{
                    Collections.shuffle(list);
                    Integer price = list.remove(0);
                    System.out.println(getName() + "又产生了一个" + price + "元大奖");
                    recordMap.computeIfAbsent(getName(), k -> new ArrayList<>()).add(price);
                    try {
                        sleep(100);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }
    }
}
